using System;
using System.Collections.Generic;
using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.HighLevel.UI;

using Sample;

namespace Nyanimals
{
	public sealed class CRenderer
	{
		private static readonly CRenderer instance = new CRenderer();
		public static CRenderer Instance
		{
			get { return instance;}
		}
	
		private GraphicsContext graphics;
		
		private int screenWidth;
		private int screenHeight;
        
        public GraphicsContext Graphics
        {
            get { return graphics;}
        }
		
		private CRenderer ()
		{
			// setup the graphics
			graphics = new GraphicsContext();
			screenWidth = graphics.Screen.Width;
			screenHeight = graphics.Screen.Height;
			graphics.SetViewport(0, 0, screenWidth, screenHeight);
			graphics.SetClearColor(0.5f, 0.5f, 0.5f, 1.0f);
			graphics.Enable( EnableMode.DepthTest ) ;
			graphics.Enable( EnableMode.CullFace ) ;
			graphics.SetCullFace( CullFaceMode.Back, CullFaceDirection.Ccw ) ;
			// init the camera
			CCamera.Instance.BuildPerspective(FMath.Radians(45.0f), ((float)screenWidth)/((float)screenHeight), 1.0f, 100000000000.0f);	
            
            UISystem.Initialize(graphics);
		}
        ~CRenderer()
        {
            UISystem.Terminate();
        }
		
		public void Render()
		{			
			CContextManager.Instance.Render(graphics);            
            UISystem.Render();
			graphics.SwapBuffers();
		}
		
	}
}

